<?php

class PrizeController extends Controller
{
	public function actions()
	{

	}

	public function actionList()
	{
		$p = intval( Yii::app()->request->getParam('p', 1) );
		$p = $p < 1 ? 1 : $p;
		$pageSize = 50;

		$modPrize = new PrizeFront();
		$modPrize->setParams(array(
			'limit' => $pageSize,
			'offset' => $pageSize * ($p - 1),
		));
		$arrList = $modPrize->getList();
		$arrTplData['count'] = $modPrize->getCount();
		$arrTplData['pageSize'] = $pageSize;
		$arrTplData["arrList"] = $arrList;
		$this->renderFile("crud/list.tpl", $arrTplData);
	}

	public function actionShow()
	{
		$id = Yii::app()->request->getParam('id');
		$modPrize = new PrizeFront();
		$modPrize->setParams(array('id' => $id));
		$model = $modPrize->getItem();
		$arrTplData['model'] = $model;
		$arrTplData['fields'] = $modPrize->fields;
		$this->renderFile('crud/show.tpl', $arrTplData);
	}

	public function actionEdit()
	{
		$id = Yii::app()->request->getParam('id');
		$modPrize = new PrizeFront();
		$modPrize->setParams(array('id' => $id));
		$model = $modPrize->getItem();
		$arrTplData['model'] = $model;
		$arrTplData['fields'] = $modPrize->fields;
		$this->renderFile('crud/edit.tpl', $arrTplData);
	}

	public function actionAdd()
	{
		$modPrize = new PrizeFront();
		$arrTplData['fields'] = $modPrize->fields;
		$this->renderFile('crud/edit.tpl', $arrTplData);
	}

	public function actionSave()
	{
		$id = intval( Yii::app()->request->getParam('id', 0) );
		$modPrize = new PrizeFront();
		$model = array();
		if($id){
			$modPrize->setParams(array('id' => $id));
			$model = $modPrize->getItem();
		}
		foreach ($modPrize->fields as $field) {
			if($field == 'id'){
				continue;
			}
			$model[$field] = Yii::app()->request->getParam($field);
		}
		$modelId = $modPrize->save($model);
		Yii::app()->request->redirect( 'show?id='.$modelId);
	}

	public function actionDelete()
	{

	}

	
}